David Pursehouse | 8898e2f | 2012-11-14 07:51:03 +0900 | [diff] [blame] | 1 | #!/usr/bin/env python |
Mike Frysinger | f601376 | 2019-06-13 02:30:51 -0400 | [diff] [blame] | 2 | # -*- coding:utf-8 -*- |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 3 | |
Mike Frysinger | 87fb5a1 | 2019-06-13 01:54:46 -0400 | [diff] [blame] | 4 | """Repo launcher. |
| 5 | |
| 6 | This is a standalone tool that people may copy to anywhere in their system. |
| 7 | It is used to get an initial repo client checkout, and after that it runs the |
| 8 | copy of repo in the checkout. |
| 9 | """ |
| 10 | |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 11 | from __future__ import print_function |
| 12 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 13 | # repo default configuration |
| 14 | # |
Mark E. Hamilton | 5553628 | 2016-02-03 15:49:43 -0700 | [diff] [blame] | 15 | import os |
| 16 | REPO_URL = os.environ.get('REPO_URL', None) |
| 17 | if not REPO_URL: |
| 18 | REPO_URL = 'https://gerrit.googlesource.com/git-repo' |
David Pursehouse | 8f62fb7 | 2012-11-14 12:09:38 +0900 | [diff] [blame] | 19 | REPO_REV = 'stable' |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 20 | |
| 21 | # Copyright (C) 2008 Google Inc. |
| 22 | # |
| 23 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 24 | # you may not use this file except in compliance with the License. |
| 25 | # You may obtain a copy of the License at |
| 26 | # |
| 27 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 28 | # |
| 29 | # Unless required by applicable law or agreed to in writing, software |
| 30 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 31 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 32 | # See the License for the specific language governing permissions and |
| 33 | # limitations under the License. |
| 34 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 35 | # increment this whenever we make important changes to this script |
Mike Frysinger | ee451f0 | 2020-02-04 00:00:08 -0500 | [diff] [blame] | 36 | VERSION = (2, 0) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 37 | |
| 38 | # increment this if the MAINTAINER_KEYS block is modified |
Mike Frysinger | f5525fb | 2020-02-04 00:01:00 -0500 | [diff] [blame] | 39 | KEYRING_VERSION = (2, 0) |
Mike Frysinger | e443365 | 2016-09-13 18:06:07 -0400 | [diff] [blame] | 40 | |
| 41 | # Each individual key entry is created by using: |
| 42 | # gpg --armor --export keyid |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 43 | MAINTAINER_KEYS = """ |
| 44 | |
| 45 | Repo Maintainer <repo@android.kernel.org> |
| 46 | -----BEGIN PGP PUBLIC KEY BLOCK----- |
| 47 | Version: GnuPG v1.4.2.2 (GNU/Linux) |
| 48 | |
| 49 | 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 |
| 84 | =CMiZ |
| 85 | -----END PGP PUBLIC KEY BLOCK----- |
| 86 | """ |
| 87 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 88 | GIT = 'git' # our git command |
Mike Frysinger | 655aedd | 2020-02-04 00:02:18 -0500 | [diff] [blame^] | 89 | MIN_GIT_VERSION = (2, 10, 2) # minimum supported git version |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 90 | repodir = '.repo' # name of repo's private directory |
| 91 | S_repo = 'repo' # special repo repository |
| 92 | S_manifests = 'manifests' # special manifest repository |
| 93 | REPO_MAIN = S_repo + '/main.py' # main script |
Eli Ribble | d4b13c2 | 2018-12-18 21:21:12 -0800 | [diff] [blame] | 94 | MIN_PYTHON_VERSION = (2, 7) # minimum supported python version |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame] | 95 | GITC_CONFIG_FILE = '/gitc/.config' |
Dan Willemsen | 745b4ad | 2015-10-06 15:23:19 -0700 | [diff] [blame] | 96 | GITC_FS_ROOT_DIR = '/gitc/manifest-rw/' |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 97 | |
| 98 | |
Mike Frysinger | 6db1b9e | 2019-07-10 15:32:36 -0400 | [diff] [blame] | 99 | import collections |
David James | bf79c66 | 2013-12-26 14:20:13 -0800 | [diff] [blame] | 100 | import errno |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 101 | import optparse |
Renaud Paquay | 35d2221 | 2016-11-01 11:24:52 -0700 | [diff] [blame] | 102 | import platform |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 103 | import re |
Mitchel Humpherys | eb5acc9 | 2014-03-12 10:48:15 -0700 | [diff] [blame] | 104 | import shutil |
Sarah Owens | 60798a3 | 2012-10-25 17:53:09 -0700 | [diff] [blame] | 105 | import stat |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 106 | import subprocess |
| 107 | import sys |
David Pursehouse | 59bbb58 | 2013-05-17 10:49:33 +0900 | [diff] [blame] | 108 | |
| 109 | if sys.version_info[0] == 3: |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 110 | import urllib.request |
| 111 | import urllib.error |
| 112 | else: |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 113 | import imp |
David Pursehouse | 59bbb58 | 2013-05-17 10:49:33 +0900 | [diff] [blame] | 114 | import urllib2 |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 115 | urllib = imp.new_module('urllib') |
| 116 | urllib.request = urllib2 |
| 117 | urllib.error = urllib2 |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 118 | |
Conley Owens | 5e0ee14 | 2013-09-26 15:50:49 -0700 | [diff] [blame] | 119 | |
Chirayu Desai | 51813df | 2013-04-16 19:36:09 +0530 | [diff] [blame] | 120 | # Python version check |
| 121 | ver = sys.version_info |
Chirayu Desai | 51813df | 2013-04-16 19:36:09 +0530 | [diff] [blame] | 122 | if (ver[0], ver[1]) < MIN_PYTHON_VERSION: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 123 | print('error: Python version {} unsupported.\n' |
| 124 | 'Please use Python {}.{} instead.'.format( |
| 125 | sys.version.split(' ')[0], |
| 126 | MIN_PYTHON_VERSION[0], |
| 127 | MIN_PYTHON_VERSION[1], |
| 128 | ), file=sys.stderr) |
Chirayu Desai | 51813df | 2013-04-16 19:36:09 +0530 | [diff] [blame] | 129 | sys.exit(1) |
| 130 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 131 | home_dot_repo = os.path.expanduser('~/.repoconfig') |
| 132 | gpg_dir = os.path.join(home_dot_repo, 'gnupg') |
| 133 | |
| 134 | extra_args = [] |
| 135 | init_optparse = optparse.OptionParser(usage="repo init -u url [options]") |
| 136 | |
| 137 | # Logging |
| 138 | group = init_optparse.add_option_group('Logging options') |
| 139 | group.add_option('-q', '--quiet', |
| 140 | dest="quiet", action="store_true", default=False, |
| 141 | help="be quiet") |
| 142 | |
| 143 | # Manifest |
| 144 | group = init_optparse.add_option_group('Manifest options') |
| 145 | group.add_option('-u', '--manifest-url', |
| 146 | dest='manifest_url', |
| 147 | help='manifest repository location', metavar='URL') |
| 148 | group.add_option('-b', '--manifest-branch', |
| 149 | dest='manifest_branch', |
| 150 | help='manifest branch or revision', metavar='REVISION') |
| 151 | group.add_option('-m', '--manifest-name', |
| 152 | dest='manifest_name', |
| 153 | help='initial manifest file', metavar='NAME.xml') |
Ereth McKnight-MacNeil | 12ee544 | 2018-12-19 21:28:35 -0800 | [diff] [blame] | 154 | group.add_option('--current-branch', |
Naseer Ahmed | f4dda9a | 2016-12-01 18:49:54 -0500 | [diff] [blame] | 155 | dest='current_branch_only', action='store_true', |
| 156 | help='fetch only current manifest branch from server') |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 157 | group.add_option('--mirror', |
| 158 | dest='mirror', action='store_true', |
David Pursehouse | 3794a78 | 2012-11-15 06:17:30 +0900 | [diff] [blame] | 159 | help='create a replica of the remote repositories ' |
| 160 | 'rather than a client working directory') |
Shawn O. Pearce | 8844338 | 2010-10-08 10:02:09 +0200 | [diff] [blame] | 161 | group.add_option('--reference', |
| 162 | dest='reference', |
| 163 | help='location of mirror directory', metavar='DIR') |
Nikolai Merinov | 09f0abb | 2018-10-19 15:07:05 +0500 | [diff] [blame] | 164 | group.add_option('--dissociate', |
| 165 | dest='dissociate', action='store_true', |
| 166 | help='dissociate from reference mirrors after clone') |
Doug Anderson | 49cd59b | 2011-06-13 21:42:06 -0700 | [diff] [blame] | 167 | group.add_option('--depth', type='int', default=None, |
| 168 | dest='depth', |
| 169 | help='create a shallow clone with given depth; see git clone') |
Xin Li | 745be2e | 2019-06-03 11:24:30 -0700 | [diff] [blame] | 170 | group.add_option('--partial-clone', action='store_true', |
| 171 | dest='partial_clone', |
| 172 | help='perform partial clone (https://git-scm.com/' |
| 173 | 'docs/gitrepository-layout#_code_partialclone_code)') |
| 174 | group.add_option('--clone-filter', action='store', default='blob:none', |
| 175 | dest='clone_filter', |
| 176 | help='filter for use with --partial-clone [default: %default]') |
Julien Campergue | 335f5ef | 2013-10-16 11:02:35 +0200 | [diff] [blame] | 177 | group.add_option('--archive', |
| 178 | dest='archive', action='store_true', |
| 179 | help='checkout an archive instead of a git repository for ' |
| 180 | 'each project. See git archive.') |
Martin Kelly | e4e94d2 | 2017-03-21 16:05:12 -0700 | [diff] [blame] | 181 | group.add_option('--submodules', |
| 182 | dest='submodules', action='store_true', |
| 183 | help='sync any submodules associated with the manifest repo') |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 184 | group.add_option('-g', '--groups', |
Conley Owens | 971de8e | 2012-04-16 10:36:08 -0700 | [diff] [blame] | 185 | dest='groups', default='default', |
David Holmer | 0a1c6a1 | 2012-11-14 19:19:00 -0500 | [diff] [blame] | 186 | help='restrict manifest projects to ones with specified ' |
| 187 | 'group(s) [default|all|G1,G2,G3|G4,-G5,-G6]', |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 188 | metavar='GROUP') |
Conley Owens | d21720d | 2012-04-16 11:02:21 -0700 | [diff] [blame] | 189 | group.add_option('-p', '--platform', |
| 190 | dest='platform', default="auto", |
Conley Owens | c9129d9 | 2012-10-01 16:12:28 -0700 | [diff] [blame] | 191 | help='restrict manifest projects to ones with a specified ' |
Conley Owens | d21720d | 2012-04-16 11:02:21 -0700 | [diff] [blame] | 192 | 'platform group [auto|all|none|linux|darwin|...]', |
| 193 | metavar='PLATFORM') |
Hu xiuyun | 9711a98 | 2015-12-11 11:16:41 +0800 | [diff] [blame] | 194 | group.add_option('--no-clone-bundle', |
| 195 | dest='no_clone_bundle', action='store_true', |
| 196 | help='disable use of /clone.bundle on HTTP/HTTPS') |
Naseer Ahmed | f4dda9a | 2016-12-01 18:49:54 -0500 | [diff] [blame] | 197 | group.add_option('--no-tags', |
| 198 | dest='no_tags', action='store_true', |
| 199 | help="don't fetch tags in the manifest") |
Doug Anderson | 49cd59b | 2011-06-13 21:42:06 -0700 | [diff] [blame] | 200 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 201 | |
| 202 | # Tool |
Shawn O. Pearce | fd89b67 | 2009-04-18 11:28:57 -0700 | [diff] [blame] | 203 | group = init_optparse.add_option_group('repo Version options') |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 204 | group.add_option('--repo-url', |
| 205 | dest='repo_url', |
| 206 | help='repo repository location', metavar='URL') |
| 207 | group.add_option('--repo-branch', |
| 208 | dest='repo_branch', |
| 209 | help='repo branch or revision', metavar='REVISION') |
| 210 | group.add_option('--no-repo-verify', |
| 211 | dest='no_repo_verify', action='store_true', |
| 212 | help='do not verify repo source code') |
| 213 | |
Victor Boivie | 841be34 | 2011-04-05 11:31:10 +0200 | [diff] [blame] | 214 | # Other |
| 215 | group = init_optparse.add_option_group('Other options') |
| 216 | group.add_option('--config-name', |
| 217 | dest='config_name', action="store_true", default=False, |
| 218 | help='Always prompt for name/e-mail') |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 219 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 220 | |
| 221 | def _GitcInitOptions(init_optparse_arg): |
| 222 | init_optparse_arg.set_usage("repo gitc-init -u url -c client [options]") |
| 223 | g = init_optparse_arg.add_option_group('GITC options') |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 224 | g.add_option('-f', '--manifest-file', |
| 225 | dest='manifest_file', |
| 226 | help='Optional manifest file to use for this GITC client.') |
| 227 | g.add_option('-c', '--gitc-client', |
| 228 | dest='gitc_client', |
Dan Willemsen | 745b4ad | 2015-10-06 15:23:19 -0700 | [diff] [blame] | 229 | help='The name of the gitc_client instance to create or modify.') |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 230 | |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame] | 231 | _gitc_manifest_dir = None |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 232 | |
| 233 | |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame] | 234 | def get_gitc_manifest_dir(): |
| 235 | global _gitc_manifest_dir |
| 236 | if _gitc_manifest_dir is None: |
Dan Willemsen | 2487cb7 | 2015-08-31 15:45:06 -0700 | [diff] [blame] | 237 | _gitc_manifest_dir = '' |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame] | 238 | try: |
| 239 | with open(GITC_CONFIG_FILE, 'r') as gitc_config: |
| 240 | for line in gitc_config: |
| 241 | match = re.match('gitc_dir=(?P<gitc_manifest_dir>.*)', line) |
| 242 | if match: |
| 243 | _gitc_manifest_dir = match.group('gitc_manifest_dir') |
| 244 | except IOError: |
Dan Willemsen | 2487cb7 | 2015-08-31 15:45:06 -0700 | [diff] [blame] | 245 | pass |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame] | 246 | return _gitc_manifest_dir |
| 247 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 248 | |
Dan Willemsen | 745b4ad | 2015-10-06 15:23:19 -0700 | [diff] [blame] | 249 | def gitc_parse_clientdir(gitc_fs_path): |
| 250 | """Parse a path in the GITC FS and return its client name. |
| 251 | |
| 252 | @param gitc_fs_path: A subdirectory path within the GITC_FS_ROOT_DIR. |
| 253 | |
| 254 | @returns: The GITC client name |
| 255 | """ |
| 256 | if gitc_fs_path == GITC_FS_ROOT_DIR: |
| 257 | return None |
| 258 | if not gitc_fs_path.startswith(GITC_FS_ROOT_DIR): |
| 259 | manifest_dir = get_gitc_manifest_dir() |
| 260 | if manifest_dir == '': |
| 261 | return None |
| 262 | if manifest_dir[-1] != '/': |
| 263 | manifest_dir += '/' |
| 264 | if gitc_fs_path == manifest_dir: |
| 265 | return None |
| 266 | if not gitc_fs_path.startswith(manifest_dir): |
| 267 | return None |
| 268 | return gitc_fs_path.split(manifest_dir)[1].split('/')[0] |
| 269 | return gitc_fs_path.split(GITC_FS_ROOT_DIR)[1].split('/')[0] |
| 270 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 271 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 272 | class CloneFailure(Exception): |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 273 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 274 | """Indicate the remote clone of repo itself failed. |
| 275 | """ |
| 276 | |
| 277 | |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 278 | def _Init(args, gitc_init=False): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 279 | """Installs repo by cloning it over the network. |
| 280 | """ |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 281 | if gitc_init: |
| 282 | _GitcInitOptions(init_optparse) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 283 | opt, args = init_optparse.parse_args(args) |
Xiaodong Xu | ae0a36c | 2012-01-31 11:10:09 +0800 | [diff] [blame] | 284 | if args: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 285 | init_optparse.print_usage() |
| 286 | sys.exit(1) |
| 287 | |
| 288 | url = opt.repo_url |
| 289 | if not url: |
| 290 | url = REPO_URL |
| 291 | extra_args.append('--repo-url=%s' % url) |
| 292 | |
| 293 | branch = opt.repo_branch |
| 294 | if not branch: |
| 295 | branch = REPO_REV |
| 296 | extra_args.append('--repo-branch=%s' % branch) |
| 297 | |
| 298 | if branch.startswith('refs/heads/'): |
| 299 | branch = branch[len('refs/heads/'):] |
| 300 | if branch.startswith('refs/'): |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 301 | print("fatal: invalid branch name '%s'" % branch, file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 302 | raise CloneFailure() |
| 303 | |
David James | bf79c66 | 2013-12-26 14:20:13 -0800 | [diff] [blame] | 304 | try: |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 305 | if gitc_init: |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame] | 306 | gitc_manifest_dir = get_gitc_manifest_dir() |
| 307 | if not gitc_manifest_dir: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 308 | print('fatal: GITC filesystem is not available. Exiting...', |
| 309 | file=sys.stderr) |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame] | 310 | sys.exit(1) |
Dan Willemsen | 745b4ad | 2015-10-06 15:23:19 -0700 | [diff] [blame] | 311 | gitc_client = opt.gitc_client |
| 312 | if not gitc_client: |
| 313 | gitc_client = gitc_parse_clientdir(os.getcwd()) |
| 314 | if not gitc_client: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 315 | print('fatal: GITC client (-c) is required.', file=sys.stderr) |
Dan Willemsen | 9ff2ece | 2015-08-31 15:45:06 -0700 | [diff] [blame] | 316 | sys.exit(1) |
Dan Willemsen | 745b4ad | 2015-10-06 15:23:19 -0700 | [diff] [blame] | 317 | client_dir = os.path.join(gitc_manifest_dir, gitc_client) |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 318 | if not os.path.exists(client_dir): |
| 319 | os.makedirs(client_dir) |
| 320 | os.chdir(client_dir) |
| 321 | if os.path.exists(repodir): |
| 322 | # This GITC Client has already initialized repo so continue. |
| 323 | return |
| 324 | |
David James | bf79c66 | 2013-12-26 14:20:13 -0800 | [diff] [blame] | 325 | os.mkdir(repodir) |
| 326 | except OSError as e: |
| 327 | if e.errno != errno.EEXIST: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 328 | print('fatal: cannot make %s directory: %s' |
| 329 | % (repodir, e.strerror), file=sys.stderr) |
David Pursehouse | 3794a78 | 2012-11-15 06:17:30 +0900 | [diff] [blame] | 330 | # Don't raise CloneFailure; that would delete the |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 331 | # name. Instead exit immediately. |
| 332 | # |
| 333 | sys.exit(1) |
| 334 | |
| 335 | _CheckGitVersion() |
| 336 | try: |
Sebastian Schuberth | 8f997b3 | 2020-01-20 11:42:48 +0100 | [diff] [blame] | 337 | if opt.no_repo_verify: |
| 338 | do_verify = False |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 339 | else: |
Sebastian Schuberth | 8f997b3 | 2020-01-20 11:42:48 +0100 | [diff] [blame] | 340 | if NeedSetupGnuPG(): |
| 341 | do_verify = SetupGnuPG(opt.quiet) |
| 342 | else: |
| 343 | do_verify = True |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 344 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 345 | dst = os.path.abspath(os.path.join(repodir, S_repo)) |
Hu xiuyun | 9711a98 | 2015-12-11 11:16:41 +0800 | [diff] [blame] | 346 | _Clone(url, dst, opt.quiet, not opt.no_clone_bundle) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 347 | |
Sebastian Schuberth | 8f997b3 | 2020-01-20 11:42:48 +0100 | [diff] [blame] | 348 | if do_verify: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 349 | rev = _Verify(dst, branch, opt.quiet) |
| 350 | else: |
| 351 | rev = 'refs/remotes/origin/%s^0' % branch |
| 352 | |
| 353 | _Checkout(dst, branch, rev, opt.quiet) |
Sebastian Schuberth | 993dcac | 2018-07-13 10:25:52 +0200 | [diff] [blame] | 354 | |
| 355 | if not os.path.isfile(os.path.join(dst, 'repo')): |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 356 | print("warning: '%s' does not look like a git-repo repository, is " |
| 357 | "REPO_URL set correctly?" % url, file=sys.stderr) |
Sebastian Schuberth | 993dcac | 2018-07-13 10:25:52 +0200 | [diff] [blame] | 358 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 359 | except CloneFailure: |
| 360 | if opt.quiet: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 361 | print('fatal: repo init failed; run without --quiet to see why', |
| 362 | file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 363 | raise |
| 364 | |
| 365 | |
Mike Frysinger | 6db1b9e | 2019-07-10 15:32:36 -0400 | [diff] [blame] | 366 | # The git version info broken down into components for easy analysis. |
| 367 | # Similar to Python's sys.version_info. |
| 368 | GitVersion = collections.namedtuple( |
| 369 | 'GitVersion', ('major', 'minor', 'micro', 'full')) |
| 370 | |
Mike Frysinger | f88b2fe | 2019-07-10 15:37:43 -0400 | [diff] [blame] | 371 | def ParseGitVersion(ver_str=None): |
| 372 | if ver_str is None: |
| 373 | # Load the version ourselves. |
| 374 | ver_str = _GetGitVersion() |
| 375 | |
Conley Owens | ff0a3c8 | 2014-01-30 14:46:03 -0800 | [diff] [blame] | 376 | if not ver_str.startswith('git version '): |
| 377 | return None |
| 378 | |
Mike Frysinger | 6db1b9e | 2019-07-10 15:32:36 -0400 | [diff] [blame] | 379 | full_version = ver_str[len('git version '):].strip() |
| 380 | num_ver_str = full_version.split('-')[0] |
Conley Owens | ff0a3c8 | 2014-01-30 14:46:03 -0800 | [diff] [blame] | 381 | to_tuple = [] |
| 382 | for num_str in num_ver_str.split('.')[:3]: |
| 383 | if num_str.isdigit(): |
| 384 | to_tuple.append(int(num_str)) |
| 385 | else: |
| 386 | to_tuple.append(0) |
Mike Frysinger | 6db1b9e | 2019-07-10 15:32:36 -0400 | [diff] [blame] | 387 | to_tuple.append(full_version) |
| 388 | return GitVersion(*to_tuple) |
Conley Owens | ff0a3c8 | 2014-01-30 14:46:03 -0800 | [diff] [blame] | 389 | |
| 390 | |
Mike Frysinger | f88b2fe | 2019-07-10 15:37:43 -0400 | [diff] [blame] | 391 | def _GetGitVersion(): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 392 | cmd = [GIT, '--version'] |
Shawn O. Pearce | 4fd38ec | 2012-06-05 07:55:07 -0700 | [diff] [blame] | 393 | try: |
| 394 | proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
Sarah Owens | a5be53f | 2012-09-09 15:37:57 -0700 | [diff] [blame] | 395 | except OSError as e: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 396 | print(file=sys.stderr) |
| 397 | print("fatal: '%s' is not available" % GIT, file=sys.stderr) |
| 398 | print('fatal: %s' % e, file=sys.stderr) |
| 399 | print(file=sys.stderr) |
| 400 | print('Please make sure %s is installed and in your path.' % GIT, |
| 401 | file=sys.stderr) |
Mike Frysinger | f88b2fe | 2019-07-10 15:37:43 -0400 | [diff] [blame] | 402 | raise |
Shawn O. Pearce | 4fd38ec | 2012-06-05 07:55:07 -0700 | [diff] [blame] | 403 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 404 | ver_str = proc.stdout.read().strip() |
| 405 | proc.stdout.close() |
Shawn O. Pearce | 1619134 | 2008-10-28 08:33:34 -0700 | [diff] [blame] | 406 | proc.wait() |
Mike Frysinger | f88b2fe | 2019-07-10 15:37:43 -0400 | [diff] [blame] | 407 | return ver_str.decode('utf-8') |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 408 | |
Mike Frysinger | f88b2fe | 2019-07-10 15:37:43 -0400 | [diff] [blame] | 409 | |
| 410 | def _CheckGitVersion(): |
| 411 | try: |
| 412 | ver_act = ParseGitVersion() |
| 413 | except OSError: |
| 414 | raise CloneFailure() |
| 415 | |
Conley Owens | ff0a3c8 | 2014-01-30 14:46:03 -0800 | [diff] [blame] | 416 | if ver_act is None: |
Mike Frysinger | 4c263b5 | 2019-09-11 04:04:16 -0400 | [diff] [blame] | 417 | print('fatal: unable to detect git version', file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 418 | raise CloneFailure() |
| 419 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 420 | if ver_act < MIN_GIT_VERSION: |
David Pursehouse | 685f080 | 2012-11-14 08:34:39 +0900 | [diff] [blame] | 421 | need = '.'.join(map(str, MIN_GIT_VERSION)) |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 422 | print('fatal: git %s or later required' % need, file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 423 | raise CloneFailure() |
| 424 | |
| 425 | |
Conley Owens | c9129d9 | 2012-10-01 16:12:28 -0700 | [diff] [blame] | 426 | def NeedSetupGnuPG(): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 427 | if not os.path.isdir(home_dot_repo): |
| 428 | return True |
| 429 | |
| 430 | kv = os.path.join(home_dot_repo, 'keyring-version') |
| 431 | if not os.path.exists(kv): |
| 432 | return True |
| 433 | |
| 434 | kv = open(kv).read() |
| 435 | if not kv: |
| 436 | return True |
| 437 | |
David Pursehouse | 685f080 | 2012-11-14 08:34:39 +0900 | [diff] [blame] | 438 | kv = tuple(map(int, kv.split('.'))) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 439 | if kv < KEYRING_VERSION: |
| 440 | return True |
| 441 | return False |
| 442 | |
| 443 | |
Conley Owens | c9129d9 | 2012-10-01 16:12:28 -0700 | [diff] [blame] | 444 | def SetupGnuPG(quiet): |
David James | bf79c66 | 2013-12-26 14:20:13 -0800 | [diff] [blame] | 445 | try: |
| 446 | os.mkdir(home_dot_repo) |
| 447 | except OSError as e: |
| 448 | if e.errno != errno.EEXIST: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 449 | print('fatal: cannot make %s directory: %s' |
| 450 | % (home_dot_repo, e.strerror), file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 451 | sys.exit(1) |
| 452 | |
David James | bf79c66 | 2013-12-26 14:20:13 -0800 | [diff] [blame] | 453 | try: |
| 454 | os.mkdir(gpg_dir, stat.S_IRWXU) |
| 455 | except OSError as e: |
| 456 | if e.errno != errno.EEXIST: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 457 | print('fatal: cannot make %s directory: %s' % (gpg_dir, e.strerror), |
| 458 | file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 459 | sys.exit(1) |
| 460 | |
Shawn O. Pearce | f18cb76 | 2010-12-07 11:41:05 -0800 | [diff] [blame] | 461 | env = os.environ.copy() |
Dāvis Mosāns | 631d0ec | 2016-07-16 21:11:11 +0300 | [diff] [blame] | 462 | try: |
| 463 | env['GNUPGHOME'] = gpg_dir |
| 464 | except UnicodeEncodeError: |
| 465 | env['GNUPGHOME'] = gpg_dir.encode() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 466 | |
| 467 | cmd = ['gpg', '--import'] |
| 468 | try: |
| 469 | proc = subprocess.Popen(cmd, |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 470 | env=env, |
| 471 | stdin=subprocess.PIPE) |
Sarah Owens | a5be53f | 2012-09-09 15:37:57 -0700 | [diff] [blame] | 472 | except OSError as e: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 473 | if not quiet: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 474 | print('warning: gpg (GnuPG) is not available.', file=sys.stderr) |
| 475 | print('warning: Installing it is strongly encouraged.', file=sys.stderr) |
| 476 | print(file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 477 | return False |
| 478 | |
Mike Frysinger | 9100f7f | 2019-09-11 03:58:36 -0400 | [diff] [blame] | 479 | proc.stdin.write(MAINTAINER_KEYS.encode('utf-8')) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 480 | proc.stdin.close() |
| 481 | |
| 482 | if proc.wait() != 0: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 483 | print('fatal: registering repo maintainer keys failed', file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 484 | sys.exit(1) |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 485 | print() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 486 | |
Mike Frysinger | 3164d40 | 2019-11-11 05:40:22 -0500 | [diff] [blame] | 487 | with open(os.path.join(home_dot_repo, 'keyring-version'), 'w') as fd: |
| 488 | fd.write('.'.join(map(str, KEYRING_VERSION)) + '\n') |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 489 | return True |
| 490 | |
| 491 | |
| 492 | def _SetConfig(local, name, value): |
| 493 | """Set a git configuration option to the specified value. |
| 494 | """ |
| 495 | cmd = [GIT, 'config', name, value] |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 496 | if subprocess.Popen(cmd, cwd=local).wait() != 0: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 497 | raise CloneFailure() |
| 498 | |
| 499 | |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 500 | def _InitHttp(): |
| 501 | handlers = [] |
| 502 | |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 503 | mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm() |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 504 | try: |
| 505 | import netrc |
| 506 | n = netrc.netrc() |
| 507 | for host in n.hosts: |
| 508 | p = n.hosts[host] |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 509 | mgr.add_password(p[1], 'http://%s/' % host, p[0], p[2]) |
Xiaodong Xu | ae0a36c | 2012-01-31 11:10:09 +0800 | [diff] [blame] | 510 | mgr.add_password(p[1], 'https://%s/' % host, p[0], p[2]) |
David Pursehouse | 65b0ba5 | 2018-06-24 16:21:51 +0900 | [diff] [blame] | 511 | except: |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 512 | pass |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 513 | handlers.append(urllib.request.HTTPBasicAuthHandler(mgr)) |
| 514 | handlers.append(urllib.request.HTTPDigestAuthHandler(mgr)) |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 515 | |
| 516 | if 'http_proxy' in os.environ: |
| 517 | url = os.environ['http_proxy'] |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 518 | handlers.append(urllib.request.ProxyHandler({'http': url, 'https': url})) |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 519 | if 'REPO_CURL_VERBOSE' in os.environ: |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 520 | handlers.append(urllib.request.HTTPHandler(debuglevel=1)) |
| 521 | handlers.append(urllib.request.HTTPSHandler(debuglevel=1)) |
| 522 | urllib.request.install_opener(urllib.request.build_opener(*handlers)) |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 523 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 524 | |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 525 | def _Fetch(url, local, src, quiet): |
| 526 | if not quiet: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 527 | print('Get %s' % url, file=sys.stderr) |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 528 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 529 | cmd = [GIT, 'fetch'] |
| 530 | if quiet: |
| 531 | cmd.append('--quiet') |
| 532 | err = subprocess.PIPE |
| 533 | else: |
| 534 | err = None |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 535 | cmd.append(src) |
| 536 | cmd.append('+refs/heads/*:refs/remotes/origin/*') |
Xin Li | 6e53844 | 2018-12-10 11:33:16 -0800 | [diff] [blame] | 537 | cmd.append('+refs/tags/*:refs/tags/*') |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 538 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 539 | proc = subprocess.Popen(cmd, cwd=local, stderr=err) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 540 | if err: |
| 541 | proc.stderr.read() |
| 542 | proc.stderr.close() |
| 543 | if proc.wait() != 0: |
| 544 | raise CloneFailure() |
| 545 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 546 | |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 547 | def _DownloadBundle(url, local, quiet): |
| 548 | if not url.endswith('/'): |
| 549 | url += '/' |
| 550 | url += 'clone.bundle' |
| 551 | |
| 552 | proc = subprocess.Popen( |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 553 | [GIT, 'config', '--get-regexp', 'url.*.insteadof'], |
| 554 | cwd=local, |
| 555 | stdout=subprocess.PIPE) |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 556 | for line in proc.stdout: |
Mike Frysinger | 9100f7f | 2019-09-11 03:58:36 -0400 | [diff] [blame] | 557 | line = line.decode('utf-8') |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 558 | m = re.compile(r'^url\.(.*)\.insteadof (.*)$').match(line) |
| 559 | if m: |
| 560 | new_url = m.group(1) |
| 561 | old_url = m.group(2) |
| 562 | if url.startswith(old_url): |
| 563 | url = new_url + url[len(old_url):] |
| 564 | break |
| 565 | proc.stdout.close() |
| 566 | proc.wait() |
| 567 | |
| 568 | if not url.startswith('http:') and not url.startswith('https:'): |
| 569 | return False |
| 570 | |
| 571 | dest = open(os.path.join(local, '.git', 'clone.bundle'), 'w+b') |
| 572 | try: |
| 573 | try: |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 574 | r = urllib.request.urlopen(url) |
| 575 | except urllib.error.HTTPError as e: |
John Törnblom | d3ddcdb | 2015-08-12 20:12:51 +0200 | [diff] [blame] | 576 | if e.code in [401, 403, 404, 501]: |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 577 | return False |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 578 | print('fatal: Cannot get %s' % url, file=sys.stderr) |
| 579 | print('fatal: HTTP error %s' % e.code, file=sys.stderr) |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 580 | raise CloneFailure() |
Sarah Owens | 1f7627f | 2012-10-31 09:21:55 -0700 | [diff] [blame] | 581 | except urllib.error.URLError as e: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 582 | print('fatal: Cannot get %s' % url, file=sys.stderr) |
| 583 | print('fatal: error %s' % e.reason, file=sys.stderr) |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 584 | raise CloneFailure() |
| 585 | try: |
| 586 | if not quiet: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 587 | print('Get %s' % url, file=sys.stderr) |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 588 | while True: |
| 589 | buf = r.read(8192) |
Mike Frysinger | 1b9adab | 2019-07-04 17:54:54 -0400 | [diff] [blame] | 590 | if not buf: |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 591 | return True |
| 592 | dest.write(buf) |
| 593 | finally: |
| 594 | r.close() |
| 595 | finally: |
| 596 | dest.close() |
| 597 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 598 | |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 599 | def _ImportBundle(local): |
| 600 | path = os.path.join(local, '.git', 'clone.bundle') |
| 601 | try: |
| 602 | _Fetch(local, local, path, True) |
| 603 | finally: |
| 604 | os.remove(path) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 605 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 606 | |
Hu xiuyun | 9711a98 | 2015-12-11 11:16:41 +0800 | [diff] [blame] | 607 | def _Clone(url, local, quiet, clone_bundle): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 608 | """Clones a git repository to a new subdirectory of repodir |
| 609 | """ |
| 610 | try: |
| 611 | os.mkdir(local) |
Sarah Owens | a5be53f | 2012-09-09 15:37:57 -0700 | [diff] [blame] | 612 | except OSError as e: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 613 | print('fatal: cannot make %s directory: %s' % (local, e.strerror), |
| 614 | file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 615 | raise CloneFailure() |
| 616 | |
| 617 | cmd = [GIT, 'init', '--quiet'] |
| 618 | try: |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 619 | proc = subprocess.Popen(cmd, cwd=local) |
Sarah Owens | a5be53f | 2012-09-09 15:37:57 -0700 | [diff] [blame] | 620 | except OSError as e: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 621 | print(file=sys.stderr) |
| 622 | print("fatal: '%s' is not available" % GIT, file=sys.stderr) |
| 623 | print('fatal: %s' % e, file=sys.stderr) |
| 624 | print(file=sys.stderr) |
| 625 | print('Please make sure %s is installed and in your path.' % GIT, |
| 626 | file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 627 | raise CloneFailure() |
| 628 | if proc.wait() != 0: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 629 | print('fatal: could not create %s' % local, file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 630 | raise CloneFailure() |
| 631 | |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 632 | _InitHttp() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 633 | _SetConfig(local, 'remote.origin.url', url) |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 634 | _SetConfig(local, |
| 635 | 'remote.origin.fetch', |
| 636 | '+refs/heads/*:refs/remotes/origin/*') |
Hu xiuyun | 9711a98 | 2015-12-11 11:16:41 +0800 | [diff] [blame] | 637 | if clone_bundle and _DownloadBundle(url, local, quiet): |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 638 | _ImportBundle(local) |
Dan Willemsen | fee390e | 2015-09-02 12:36:30 -0700 | [diff] [blame] | 639 | _Fetch(url, local, 'origin', quiet) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 640 | |
| 641 | |
| 642 | def _Verify(cwd, branch, quiet): |
| 643 | """Verify the branch has been signed by a tag. |
| 644 | """ |
| 645 | cmd = [GIT, 'describe', 'origin/%s' % branch] |
| 646 | proc = subprocess.Popen(cmd, |
| 647 | stdout=subprocess.PIPE, |
| 648 | stderr=subprocess.PIPE, |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 649 | cwd=cwd) |
Mike Frysinger | 9100f7f | 2019-09-11 03:58:36 -0400 | [diff] [blame] | 650 | cur = proc.stdout.read().strip().decode('utf-8') |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 651 | proc.stdout.close() |
| 652 | |
| 653 | proc.stderr.read() |
| 654 | proc.stderr.close() |
| 655 | |
| 656 | if proc.wait() != 0 or not cur: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 657 | print(file=sys.stderr) |
| 658 | print("fatal: branch '%s' has not been signed" % branch, file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 659 | raise CloneFailure() |
| 660 | |
| 661 | m = re.compile(r'^(.*)-[0-9]{1,}-g[0-9a-f]{1,}$').match(cur) |
| 662 | if m: |
| 663 | cur = m.group(1) |
| 664 | if not quiet: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 665 | print(file=sys.stderr) |
| 666 | print("info: Ignoring branch '%s'; using tagged release '%s'" |
| 667 | % (branch, cur), file=sys.stderr) |
| 668 | print(file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 669 | |
Shawn O. Pearce | f18cb76 | 2010-12-07 11:41:05 -0800 | [diff] [blame] | 670 | env = os.environ.copy() |
Dāvis Mosāns | 631d0ec | 2016-07-16 21:11:11 +0300 | [diff] [blame] | 671 | try: |
| 672 | env['GNUPGHOME'] = gpg_dir |
| 673 | except UnicodeEncodeError: |
| 674 | env['GNUPGHOME'] = gpg_dir.encode() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 675 | |
| 676 | cmd = [GIT, 'tag', '-v', cur] |
| 677 | proc = subprocess.Popen(cmd, |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 678 | stdout=subprocess.PIPE, |
| 679 | stderr=subprocess.PIPE, |
| 680 | cwd=cwd, |
| 681 | env=env) |
Mike Frysinger | 9100f7f | 2019-09-11 03:58:36 -0400 | [diff] [blame] | 682 | out = proc.stdout.read().decode('utf-8') |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 683 | proc.stdout.close() |
| 684 | |
Mike Frysinger | 9100f7f | 2019-09-11 03:58:36 -0400 | [diff] [blame] | 685 | err = proc.stderr.read().decode('utf-8') |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 686 | proc.stderr.close() |
| 687 | |
| 688 | if proc.wait() != 0: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 689 | print(file=sys.stderr) |
| 690 | print(out, file=sys.stderr) |
| 691 | print(err, file=sys.stderr) |
| 692 | print(file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 693 | raise CloneFailure() |
| 694 | return '%s^0' % cur |
| 695 | |
| 696 | |
| 697 | def _Checkout(cwd, branch, rev, quiet): |
| 698 | """Checkout an upstream branch into the repository and track it. |
| 699 | """ |
| 700 | cmd = [GIT, 'update-ref', 'refs/heads/default', rev] |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 701 | if subprocess.Popen(cmd, cwd=cwd).wait() != 0: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 702 | raise CloneFailure() |
| 703 | |
| 704 | _SetConfig(cwd, 'branch.default.remote', 'origin') |
| 705 | _SetConfig(cwd, 'branch.default.merge', 'refs/heads/%s' % branch) |
| 706 | |
| 707 | cmd = [GIT, 'symbolic-ref', 'HEAD', 'refs/heads/default'] |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 708 | if subprocess.Popen(cmd, cwd=cwd).wait() != 0: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 709 | raise CloneFailure() |
| 710 | |
| 711 | cmd = [GIT, 'read-tree', '--reset', '-u'] |
| 712 | if not quiet: |
| 713 | cmd.append('-v') |
| 714 | cmd.append('HEAD') |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 715 | if subprocess.Popen(cmd, cwd=cwd).wait() != 0: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 716 | raise CloneFailure() |
| 717 | |
| 718 | |
| 719 | def _FindRepo(): |
| 720 | """Look for a repo installation, starting at the current directory. |
| 721 | """ |
Mickaël Salaün | 2f6ab7f | 2012-09-30 00:37:55 +0200 | [diff] [blame] | 722 | curdir = os.getcwd() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 723 | repo = None |
| 724 | |
Anthony Newnam | df14a70 | 2011-01-09 17:31:57 -0800 | [diff] [blame] | 725 | olddir = None |
Mickaël Salaün | 2f6ab7f | 2012-09-30 00:37:55 +0200 | [diff] [blame] | 726 | while curdir != '/' \ |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 727 | and curdir != olddir \ |
| 728 | and not repo: |
Mickaël Salaün | 2f6ab7f | 2012-09-30 00:37:55 +0200 | [diff] [blame] | 729 | repo = os.path.join(curdir, repodir, REPO_MAIN) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 730 | if not os.path.isfile(repo): |
| 731 | repo = None |
Mickaël Salaün | 2f6ab7f | 2012-09-30 00:37:55 +0200 | [diff] [blame] | 732 | olddir = curdir |
| 733 | curdir = os.path.dirname(curdir) |
| 734 | return (repo, os.path.join(curdir, repodir)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 735 | |
| 736 | |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 737 | class _Options(object): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 738 | help = False |
| 739 | |
| 740 | |
| 741 | def _ParseArguments(args): |
| 742 | cmd = None |
| 743 | opt = _Options() |
| 744 | arg = [] |
| 745 | |
Sarah Owens | a6053d5 | 2012-11-01 13:36:50 -0700 | [diff] [blame] | 746 | for i in range(len(args)): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 747 | a = args[i] |
| 748 | if a == '-h' or a == '--help': |
| 749 | opt.help = True |
| 750 | |
| 751 | elif not a.startswith('-'): |
| 752 | cmd = a |
| 753 | arg = args[i + 1:] |
| 754 | break |
| 755 | return cmd, opt, arg |
| 756 | |
| 757 | |
| 758 | def _Usage(): |
Dan Willemsen | 9ff2ece | 2015-08-31 15:45:06 -0700 | [diff] [blame] | 759 | gitc_usage = "" |
| 760 | if get_gitc_manifest_dir(): |
| 761 | gitc_usage = " gitc-init Initialize a GITC Client.\n" |
| 762 | |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 763 | print( |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 764 | """usage: repo COMMAND [ARGS] |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 765 | |
| 766 | repo is not yet installed. Use "repo init" to install it here. |
| 767 | |
| 768 | The most commonly used repo commands are: |
| 769 | |
| 770 | init Install repo in the current working directory |
Dan Willemsen | 9ff2ece | 2015-08-31 15:45:06 -0700 | [diff] [blame] | 771 | """ + gitc_usage + |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 772 | """ help Display detailed help on a command |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 773 | |
| 774 | For access to the full online help, install repo ("repo init"). |
Mike Frysinger | 35159ab | 2019-06-13 00:07:13 -0400 | [diff] [blame] | 775 | """) |
| 776 | sys.exit(0) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 777 | |
| 778 | |
| 779 | def _Help(args): |
| 780 | if args: |
| 781 | if args[0] == 'init': |
| 782 | init_optparse.print_help() |
Trond Norbye | d3fd537 | 2011-01-03 11:35:15 +0100 | [diff] [blame] | 783 | sys.exit(0) |
Dan Willemsen | 9ff2ece | 2015-08-31 15:45:06 -0700 | [diff] [blame] | 784 | elif args[0] == 'gitc-init': |
| 785 | _GitcInitOptions(init_optparse) |
| 786 | init_optparse.print_help() |
| 787 | sys.exit(0) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 788 | else: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 789 | print("error: '%s' is not a bootstrap command.\n" |
| 790 | ' For access to online help, install repo ("repo init").' |
| 791 | % args[0], file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 792 | else: |
| 793 | _Usage() |
| 794 | sys.exit(1) |
| 795 | |
| 796 | |
| 797 | def _NotInstalled(): |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 798 | print('error: repo is not installed. Use "repo init" to install it here.', |
| 799 | file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 800 | sys.exit(1) |
| 801 | |
| 802 | |
| 803 | def _NoCommands(cmd): |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 804 | print("""error: command '%s' requires repo to be installed first. |
| 805 | Use "repo init" to install it here.""" % cmd, file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 806 | sys.exit(1) |
| 807 | |
| 808 | |
| 809 | def _RunSelf(wrapper_path): |
| 810 | my_dir = os.path.dirname(wrapper_path) |
| 811 | my_main = os.path.join(my_dir, 'main.py') |
| 812 | my_git = os.path.join(my_dir, '.git') |
| 813 | |
| 814 | if os.path.isfile(my_main) and os.path.isdir(my_git): |
Shawn O. Pearce | c8a300f | 2009-05-18 13:19:57 -0700 | [diff] [blame] | 815 | for name in ['git_config.py', |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 816 | 'project.py', |
| 817 | 'subcmds']: |
| 818 | if not os.path.exists(os.path.join(my_dir, name)): |
| 819 | return None, None |
| 820 | return my_main, my_git |
| 821 | return None, None |
| 822 | |
| 823 | |
| 824 | def _SetDefaultsTo(gitdir): |
| 825 | global REPO_URL |
| 826 | global REPO_REV |
| 827 | |
| 828 | REPO_URL = gitdir |
| 829 | proc = subprocess.Popen([GIT, |
| 830 | '--git-dir=%s' % gitdir, |
| 831 | 'symbolic-ref', |
| 832 | 'HEAD'], |
Mark E. Hamilton | 4088eb4 | 2016-02-10 10:44:30 -0700 | [diff] [blame] | 833 | stdout=subprocess.PIPE, |
| 834 | stderr=subprocess.PIPE) |
Mike Frysinger | 9100f7f | 2019-09-11 03:58:36 -0400 | [diff] [blame] | 835 | REPO_REV = proc.stdout.read().strip().decode('utf-8') |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 836 | proc.stdout.close() |
| 837 | |
| 838 | proc.stderr.read() |
| 839 | proc.stderr.close() |
| 840 | |
| 841 | if proc.wait() != 0: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 842 | print('fatal: %s has no current branch' % gitdir, file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 843 | sys.exit(1) |
| 844 | |
| 845 | |
| 846 | def main(orig_args): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 847 | cmd, opt, args = _ParseArguments(orig_args) |
| 848 | |
Dan Willemsen | 745b4ad | 2015-10-06 15:23:19 -0700 | [diff] [blame] | 849 | repo_main, rel_repo_dir = None, None |
| 850 | # Don't use the local repo copy, make sure to switch to the gitc client first. |
| 851 | if cmd != 'gitc-init': |
| 852 | repo_main, rel_repo_dir = _FindRepo() |
| 853 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 854 | wrapper_path = os.path.abspath(__file__) |
| 855 | my_main, my_git = _RunSelf(wrapper_path) |
| 856 | |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame] | 857 | cwd = os.getcwd() |
Dan Willemsen | 2487cb7 | 2015-08-31 15:45:06 -0700 | [diff] [blame] | 858 | if get_gitc_manifest_dir() and cwd.startswith(get_gitc_manifest_dir()): |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 859 | print('error: repo cannot be used in the GITC local manifest directory.' |
| 860 | '\nIf you want to work on this GITC client please rerun this ' |
| 861 | 'command from the corresponding client under /gitc/', |
| 862 | file=sys.stderr) |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame] | 863 | sys.exit(1) |
Mickaël Salaün | 2f6ab7f | 2012-09-30 00:37:55 +0200 | [diff] [blame] | 864 | if not repo_main: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 865 | if opt.help: |
| 866 | _Usage() |
| 867 | if cmd == 'help': |
| 868 | _Help(args) |
| 869 | if not cmd: |
| 870 | _NotInstalled() |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 871 | if cmd == 'init' or cmd == 'gitc-init': |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 872 | if my_git: |
| 873 | _SetDefaultsTo(my_git) |
| 874 | try: |
Simran Basi | 1efc2b4 | 2015-08-05 15:04:22 -0700 | [diff] [blame] | 875 | _Init(args, gitc_init=(cmd == 'gitc-init')) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 876 | except CloneFailure: |
Sebastian Schuberth | 27226e7 | 2016-10-28 14:27:43 +0200 | [diff] [blame] | 877 | path = os.path.join(repodir, S_repo) |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 878 | print("fatal: cloning the git-repo repository failed, will remove " |
| 879 | "'%s' " % path, file=sys.stderr) |
Sebastian Schuberth | 27226e7 | 2016-10-28 14:27:43 +0200 | [diff] [blame] | 880 | shutil.rmtree(path, ignore_errors=True) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 881 | sys.exit(1) |
Mickaël Salaün | 2f6ab7f | 2012-09-30 00:37:55 +0200 | [diff] [blame] | 882 | repo_main, rel_repo_dir = _FindRepo() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 883 | else: |
| 884 | _NoCommands(cmd) |
| 885 | |
| 886 | if my_main: |
Mickaël Salaün | 2f6ab7f | 2012-09-30 00:37:55 +0200 | [diff] [blame] | 887 | repo_main = my_main |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 888 | |
David Pursehouse | 685f080 | 2012-11-14 08:34:39 +0900 | [diff] [blame] | 889 | ver_str = '.'.join(map(str, VERSION)) |
anatoly techtonik | 3a2a59e | 2013-09-21 19:29:10 +0300 | [diff] [blame] | 890 | me = [sys.executable, repo_main, |
Mickaël Salaün | 2f6ab7f | 2012-09-30 00:37:55 +0200 | [diff] [blame] | 891 | '--repo-dir=%s' % rel_repo_dir, |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 892 | '--wrapper-version=%s' % ver_str, |
| 893 | '--wrapper-path=%s' % wrapper_path, |
| 894 | '--'] |
| 895 | me.extend(orig_args) |
| 896 | me.extend(extra_args) |
| 897 | try: |
Renaud Paquay | 35d2221 | 2016-11-01 11:24:52 -0700 | [diff] [blame] | 898 | if platform.system() == "Windows": |
| 899 | sys.exit(subprocess.call(me)) |
| 900 | else: |
| 901 | os.execv(sys.executable, me) |
Sarah Owens | a5be53f | 2012-09-09 15:37:57 -0700 | [diff] [blame] | 902 | except OSError as e: |
Mike Frysinger | c92ce5c | 2019-06-13 01:14:23 -0400 | [diff] [blame] | 903 | print("fatal: unable to start %s" % repo_main, file=sys.stderr) |
| 904 | print("fatal: %s" % e, file=sys.stderr) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 905 | sys.exit(148) |
| 906 | |
| 907 | |
| 908 | if __name__ == '__main__': |
| 909 | main(sys.argv[1:]) |